﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Permission.aspx.cs" Inherits="Modules_HeThong_PhanQuyen_PhanQuyen" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <script language="javascript">


        var commandHandler = function (cmd, record) {
            switch (cmd) {

                case "delete":
                    Ext.Msg.confirm('Xác nhận', '<span style="color:red;">Loại người dùng:</span><b> ' + record.data.UserName + '</b>', function (btn) {
                        if (btn == "yes") {
                            Ext.net.DirectMethods.DeleteUser(record.data.UserName, {
                                success: function (result) {
                                    var myMask = new Ext.LoadMask(GridPanel1.getBody(), { msg: "Tải form..." });
                                    myMask.hide();
                                    GridPanel1.store.load();
                                    Ext.Msg.hide();
                                },
                                before: function () {
                                    var myMask = new Ext.LoadMask(GridPanel1.getBody(), { msg: "Loại người dùng..." });
                                    myMask.show();
                                }
                            });
                        }
                    });
                    break;
            }
        }

        var ClickNode = function (record) {
            hdfRole.setValue(record.id);
            storeUserPermission.reload();
        }

        var date = function (value, p, record) {
            if (value == null) return "";
            value = value.replace(" ", "T");
            var temp = value.split("T");
            var date = temp[0].split("-");
            var dateStr = date[2] + "/" + date[1] + "/" + date[0];
            return dateStr;
        }

        var HotRerender = function (value, p, record) {
            if (value == true) return "<img src='bullet_green.png' alt='' />";
            return "<img src='bullet_red.png' alt='' />";
        }


        var applyFilter = function () {
            if (txtFilter.getValue() != '') {
                storeUser.reload();
            }
        }
    </script>
    <ext:Hidden runat="server" ID="hdfRole">
    </ext:Hidden>
    <ext:Viewport ID="ViewPort2" runat="server" Layout="BorderLayout">
        <Items>
            <ext:TreePanel ID="treePermission" runat="server" AutoScroll="true" Visible="true"
                Margins="5" Region="West" Icon="Key" Collapsible="false" Collapsed="false" Title="Danh sách quyền"
                BodyStyle="text-align:left;" Width="180" SingleExpand="false">
                <Listeners>
                    <Click Handler="ClickNode(node)" />
                </Listeners>
            </ext:TreePanel>
            <ext:GridPanel ID="GridPanel1" runat="server" StripeRows="true" Header="false" Border="true"
                AutoExpandColumn="Email" Margins="5 5 5 0" Region="Center" Layout="fit" TrackMouseOver="true"
                Title="Danh sách tin bài">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server" Flat="false">
                        <Items>
                            <ext:Button ID="tlbSearch_u" runat="server" Icon="Add" Text="Thêm người dùng">
                                <Listeners>
                                    <Click Handler="wdUserList.show(); store1.reload();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:CommandColumn Width="30">
                            <Commands>
                                <ext:GridCommand Icon="Delete" CommandName="delete" ToolTip-Text="<b style='color:red;'>Loại</b>" />
                            </Commands>
                        </ext:CommandColumn>
                        <ext:Column Header="Tên đăng nhập" Sortable="true" DataIndex="UserName">
                        </ext:Column>
                        <ext:Column Header="Email" Sortable="true" DataIndex="Email">
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" StoreID="storeUserPermission" PageSize="20"
                        BeforePageText="Trang&nbsp;" PrevText="Trước" FirstText="Đầu" AfterPageText=""
                        EmptyMsg="Hiện tại chưa có mẫu tin nào" RefreshText="Làm mới" LastText="Cuối"
                        NextText="Tiếp" DisplayMsg="{0}-{1}/{2}" />
                </BottomBar>
                <Listeners>
                    <Command Handler="commandHandler(command, record);" />
                </Listeners>
                <LoadMask ShowMask="true" Msg="Đang nạp dữ liệu...." />
                <Store>
                    <ext:Store ID="storeUserPermission" runat="server">
                        <Reader>
                            <ext:JsonReader Root="users" TotalProperty="totalCount" IDProperty="UserName">
                                <Fields>
                                    <ext:RecordField Name="UserName" Type="String" />
                                    <ext:RecordField Name="Email" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <BaseParams>
                            <ext:Parameter Name="query" Value="#{hdfRole}.getValue()" Mode="Raw" />
                        </BaseParams>
                        <Proxy>
                            <ext:HttpProxy Method="GET" Json="true" Url="PermissionHandler.ashx" />
                        </Proxy>
                    </ext:Store>
                </Store>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <ext:Window ID="wdUserList" runat="server" Collapsible="false" Icon="UserEdit" Title="Danh sách người dùng"
        Layout="BorderLayout" Visible="true" Hidden="true" Header="true" Modal="false"
        Height="380" BodyStyle="" Width="360">
        <Buttons>
            <ext:Button Icon="Disk" Text="Lưu">
                <DirectEvents>
                    <Click OnEvent="UpdateUser" Before=" Ext.Msg.wait('Cập nhật dữ liệu ...', 'Saving'); ">
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button Icon="ArrowUndo" Text="Hủy bỏ">
                <Listeners>
                    <Click Handler=" wdUserList.hide();" />
                </Listeners>
            </ext:Button>
        </Buttons>
        <Items>
            <ext:GridPanel ID="GridPanel2" runat="server" StripeRows="true" Header="false" Border="false"
                AutoExpandColumn="Email" Layout="Fit" Region="Center" TrackMouseOver="true" Title="Danh sách tin bài"
                Height="120">
                <ColumnModel ID="ColumnModel2" runat="server">
                    <Columns>
                        <ext:Column Header="Tên đăng nhập" Sortable="true" DataIndex="UserName">
                        </ext:Column>
                        <ext:Column Header="Email" Sortable="true" DataIndex="Email">
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:CheckboxSelectionModel runat="server" ID="selection1">
                    </ext:CheckboxSelectionModel>
                </SelectionModel>
                <Store>
                    <ext:Store ID="store1" runat="server" AutoLoad="false">
                        <Reader>
                            <ext:JsonReader Root="users" TotalProperty="totalCount" IDProperty="UserName">
                                <Fields>
                                    <ext:RecordField Name="UserName" Type="String" />
                                    <ext:RecordField Name="Email" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <Proxy>
                            <ext:HttpProxy Method="GET" Json="true" Url="UserHandler.ashx" />
                        </Proxy>
                    </ext:Store>
                </Store>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar2" runat="server" StoreID="store1" PageSize="20"
                        BeforePageText="Trang&nbsp;" PrevText="Trước" FirstText="Đầu" AfterPageText=""
                        EmptyMsg="Hiện tại chưa có mẫu tin nào" RefreshText="Làm mới" LastText="Cuối"
                        NextText="Tiếp" DisplayMsg="{0}-{1}/{2}" />
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Window>
    </form>
</body>
</html>
